package edu.ntu.cloudroid.model.policy;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import edu.ntu.cloudroid.model.IDs;
import edu.ntu.cloudroid.model.UserData;
import edu.ntu.cloudroid.xacml.builder.policy.AbstractPolicyBuilder;
import edu.ntu.cloudroid.xacml.builder.policy.SimpleFilteringBuilder;
import edu.ntu.cloudroid.xacml.builder.policy.SimpleGranularityBuilder;
import edu.ntu.cloudroid.xacml.obligation.GranularityObligation;
import edu.ntu.cloudroid.xacml.obligation.ObligationHandle;
import edu.ntu.cloudroid.xacml.obligation.FilteringObligation;

@PersistenceCapable(detachable = "true")
@Inheritance
public class SimpleGranularity extends AbstractPrivacyPreference implements
		Serializable {
	@Persistent
	int granualityLevel;

	@Override
	public AbstractPolicyBuilder getPolicyBuilder() {
		return new SimpleGranularityBuilder();
	}


	public int getGranualityLevel() {
		return this.granualityLevel;
	}

	@Override
	public void initializePreference(String[] values) throws Exception {
		int i = 0;
		this.granualityLevel = new Integer(values[i]).intValue();
		i++;
		this.setDataColumnIndex(new Integer(values[i]).intValue());
		i++;
		this.setLatestDataOnly(new Boolean(values[i]).booleanValue());
		i++;
	}

	@Override
	public UserData getMetaData(Object param) throws Exception {
		String type="";
		if (param==null)
			type = type+AbstractPrivacyPreference.ISALL;
		else
			type = type+AbstractPrivacyPreference.ISGROUP+","+param.toString();
		
		String s = this.getUserName()+","+IDs.PolicyID.SimpleGranularity.ordinal() + ","
				+ type + "," + this.granualityLevel
				+ "," + this.getDataColumnIndex()+","+this.isLatestDataOnly();
		return new PolicyInfo(this.getUserName(), s.split(","));
	}

}
